package com.example.jwt.service;


import com.example.jwt.entity.LoginUser;
import com.example.jwt.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户登录认证授权
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //todo 从数据库中查询用户信息，这里简单模拟一下
        List<String> list = new ArrayList<>();
        User user = new User();
        user.setId((long) 1);
        user.setUsername("admin");
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

        String password = passwordEncoder.encode("12345");

        user.setPassword(password);
        list.add("admin");
        list.add("system:user:list");
        return new LoginUser(user, list);
    }
}
